from enum import IntEnum, unique

import peewee as pw

from db.base_model import BaseModel


class Advices(BaseModel):
    @unique
    class Status(IntEnum):
        WAIT_ACCEPT = 1
        NOT_ACCEPT = 2
        ACCEPTED = 3
        COMPLETED = 4

    user_id = pw.CharField(max_length=128)
    content = pw.TextField()
    status = pw.SmallIntegerField(default=Status.WAIT_ACCEPT.value)

    class Meta:
        table_name = "advices"

    @classmethod
    def get_advices(cls):
        advices = cls.select().order_by(cls.id.desc())
        return advices

    @classmethod
    def delete_advice(cls, user_id, content_id):
        advice = cls.get(cls.user_id == user_id, cls.id == content_id)
        advice.delete_instance()
        return advice
